package com.ruoyi.business.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.business.domain.OrderFee;
import com.ruoyi.business.domain.vo.OrderFeeVo;
import com.ruoyi.common.core.mapper.BaseMapperPlus;

import java.util.List;

/**
 * 订单费用Mapper接口
 *
 * @author ruoyi
 * @date 2024-04-20
 */
public interface OrderFeeMapper extends BaseMapperPlus<OrderFeeMapper, OrderFee, OrderFeeVo> {

    /**
     * 根据主表id和子表name查询
     *
     * @param masterId
     * @param itemName
     * @return
     */
    default OrderFee selectByIdAndName(Long masterId, String itemName) {
        return selectOne(new QueryWrapper<OrderFee>()
            .lambda()
            .eq(OrderFee::getOrderId, masterId)
            .eq(OrderFee::getName, itemName)
            .last("limit 1"));
    }

    default List<OrderFeeVo> selectVoListByMasterId(Long masterId) {
        return selectVoList(new QueryWrapper<OrderFee>()
            .lambda()
            .eq(OrderFee::getOrderId, masterId));
    }

    default List<OrderFee> selectListByMasterId(Long masterId) {
        return selectList(new QueryWrapper<OrderFee>()
            .lambda()
            .eq(OrderFee::getOrderId, masterId));
    }

    /**
     * 根据主表id删除
     *
     * @param masterId
     * @return
     */
    default int deleteByMasterId(Long masterId) {
        return delete(new QueryWrapper<OrderFee>()
            .lambda()
            .eq(OrderFee::getOrderId, masterId));
    }
}
